<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "en_english".
 *
 * @property int $id 知识ID
 * @property int $c1 一级分类
 * @property int $c2 二级分类
 * @property int $c3 三级分类
 * @property int $cid 分类ID
 * @property string $word 单词
 * @property string $ipa_en 音标，英
 * @property string $ipa_us 音标，美
 * @property string $trans 中文翻译
 * @property int $junior 是否初中级别：0否 1是
 * @property int $senior 是否高中级别：0否 1是
 * @property int $cet4 是否CET4级别：0否 1是
 * @property int $cet6 是否CET6级别：0否 1是
 * @property int $ielts TAG 雅思：0否 1是
 * @property int $graduated 毕业的
 * @property int $create_time 发布时间
 * @property int $update_time 更新时间
 * @property int $displayorder 显示顺序
 * @property int $status 状态：-2删除，-1草稿，0待定，1正常
 */
class English extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'en_english';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['c1', 'c2', 'c3', 'cid', 'junior', 'senior', 'cet4', 'cet6', 'ielts', 'graduated', 'create_time', 'update_time', 'displayorder', 'status'], 'integer'],
            [['word', 'ipa_en', 'ipa_us'], 'string', 'max' => 100],
            [['trans'], 'string', 'max' => 1000],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'c1' => 'C1',
            'c2' => 'C2',
            'c3' => 'C3',
            'cid' => 'Cid',
            'word' => 'Word',
            'ipa_en' => 'Ipa En',
            'ipa_us' => 'Ipa Us',
            'trans' => 'Trans',
            'junior' => 'Junior',
            'senior' => 'Senior',
            'cet4' => 'Cet4',
            'cet6' => 'Cet6',
            'ielts' => 'Ielts',
            'graduated' => 'Graduated',
            'create_time' => 'Create Time',
            'update_time' => 'Update Time',
            'displayorder' => 'Displayorder',
            'status' => 'Status',
        ];
    }

    /**
     * 得到最后的顺序
     * @return int
     * @throws \yii\db\Exception
     */
    public static function getLastOrder(){
        $db = Yii::$app->db;
        $sql = "SELECT e.displayorder FROM {{%english}} AS e ORDER BY e.displayorder DESC LIMIT 1";
        $order = $db->createCommand($sql)->queryScalar();
        return intval($order);
    }

}
